package com.example.webservice.server;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ctc.wstx.evt.WDTD;
import com.example.webservice.entity.IhBed;
import com.example.webservice.entity.User;
import com.example.webservice.entity.WebServiceResult;
import org.springframework.stereotype.Component;

import javax.jws.WebService;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 彭长云
 * @Description:webservice接口实现类
 * @date 2019/1/7 11:28
 */
@WebService(serviceName = "TestService",
        targetNamespace = "http://com.example.webservice",
        endpointInterface = "com.example.webservice.server.TestService")
@Component
public class TestServiceImpl implements TestService{
    @Override
    public String login(String name, String pwd) {
        if("admin".equals(name) && "123".equals(pwd)){
            return "登陆成功";
        }
        return "登陆失败";
    }

    @Override
    public String getUserList() {
        List<User> userlist = new ArrayList<>();
        userlist.add(new User("张三",22));
        userlist.add(new User("李四",18));
        userlist.add(new User("王五",32));
        userlist.add(new User("赵六",72));
        return objectToJsonStr(userlist);
    }

    @Override
    public String getihbed(String date) {
        System.out.printf("查询%s的数据\n",date);
        List<IhBed> list = new ArrayList<>();
        for(int i = 0;i<200000;i++){
            list.add(new IhBed(i+"","cw"+i,"001","20181209","床位"+i,"1","1"));
        }
        WebServiceResult<IhBed> wr = new WebServiceResult<>();
        wr.setAddlist(list);
        wr.setUpdatelist(new ArrayList<>());
        wr.setMsg("查询成功!");
        wr.setStatus("1");
        wr.setPageSize(3);
        wr.setPageIndex(1);
        wr.setTotalCount(500);
        return objectToJsonStr(wr);
    }

    public String objectToJsonStr(Object obj){
        return JSON.toJSONString(obj);
    }
}
